<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
<fieldset class="layui-elem-field">
    <legend>修改菜单</legend>
    <div class="layui-field-box">
        <form class="layui-form">

            <div class="layui-form-item">
                <label class="layui-form-label">优惠编号</label>
                <div class="layui-input-block">
                    <input style="width:190px;" id="disno" name="disNo" required lay-verify="required"
                           autocomplete="off" class="layui-input"   value="${result.disNo!''}" >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">优惠名称</label>
                <div class="layui-input-block">
                    <input style="width:190px;" id="disname" name="disName" required lay-verify="required" autocomplete="off" class="layui-input"   value="${result.dis_name!''}" >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">优惠类型</label>
                <div class="layui-input-inline">
                    <select id="contype" name="conType" lay-verify="required" lay-filter="contype">
                        <option value="${result.con_type!''}">${result.con_type!''}</option>
                        <option value="满减">满减</option>
                        <option value="立减">立减</option>
                        <option value="折扣">折扣</option>
                        <option value="返现">返现</option>
                        <option value="积分">积分</option>
                        <option value="包邮">包邮</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">条件名称</label>
                <div class="layui-input-inline">
                    <select id="conno" name="conNo" lay-verify="required">
                    <#--根据优惠类型  从促销类型查找  查出有哪些优惠-->
                        <option value="${result.con_no!''}">${result.con_name!''}</option>
                    </select>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">优惠值</label>
                <div class="layui-input-block">
                    <input style="width:190px;" id="disvalue" name="disValue" required lay-verify="required"
                           placeholder="请输入优惠名称" autocomplete="off" class="layui-input"  value="${result.dis_value!''}"  >
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="Form">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</fieldset>


<script type="text/javascript" src="/static/layui/layui.js"></script>
<script>

    layui.use(['form', 'jquery', 'layer'], function () {
        var $ = layui.jquery;
        var form = layui.form();
        var layer = layui.layer;

        //监听提交
        form.on('submit(Form)', function (params) {
            //等同于上面注释掉的部分
            var data = $("form").serializeArray();
            $.ajax({
                type: "POST",
                url: "/act/updateDis",  //后台程序地址
                data: data,  //需要post的数据
                success: function (data) {           //后台程序返回的标签，比如我喜欢使用1和0 表示成功或者失败
                    if (data.result == 'success') {   //如果成功了, 则关闭当前layer
                        layer.msg('修改成功', {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function () {//
                            //do something
                            //注册成功后，自动关闭当前注册页面
                            //先得到当前iframe层的索引
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            //parent.layer.closeAll("iframe");
                        });
                    }
                }
            });
            return false;//return false 表示不通过页面刷新方式提交表单
        });

        form.on("select(contype)", function (data) {
            $.ajax({
                url: "/act/selectConNoByConType?conType=" + data.value,
                type: "POST",
                data: data.field,
                success: function (data) {
                    $("#conno").find('option').remove();
                    for (var i = 0; i < data.length; i++) {
                        $("#conno").append("<option value='" + data[i].con_no + "'>" + data[i].con_name + "</option>");
                    }
                    // 重新渲染页面
                    form.render();
                }
            });

        });
    });
</script>
</body>
</html>